﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QConnectSDK.Context;
using QConnectSDK;

namespace olierFrm.OAuth.Controllers
{
    public class QQController : Controller
    {
        //
        // GET: /QQ/

        public JsonResult Index()
        {
            if (Request.QueryString["type"] != null && Request.QueryString["type"] == "login")
            {
                var context = new QzoneContext();
                string state = Guid.NewGuid().ToString().Replace("-", "");
                string scope = "get_user_info,add_share,list_album,upload_pic,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idolist,add_idol,del_idol,add_one_blog,add_topic,get_tenpay_addr";
                var authenticationUrl = context.GetAuthorizationUrl(Session.SessionID, scope);
                Response.Redirect(authenticationUrl);
            }
            else if (Request.Params["code"] != null)
            {
                var verifier = Request.Params["code"];
                var qzone = new QOpenClient(verifier, Session.SessionID);
                var user = qzone.GetCurrentUser();
                //qzone.OAuthToken.OpenId;
                //user.Nickname
            }
            else
            {
                throw new HttpException(404, "没有找到该页！");
            }
            return null;
        }

    }
}
